//
// Created by Administrator on 2021/9/29.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

class Solution {
public:
    int findMinMoves(vector<int> &machines) {
        int total = accumulate(machines.begin(), machines.end(), 0);
        int n = (int) machines.size();
        if (total % n != 0)
            return -1;
        int avg = total / n;
        int ans = 0, sum = 0;
        for (int num:machines) {
            num -= avg;
            sum += num;
            ans = max(ans, max(abs(sum), num));
        }
        return ans;
    }
};

int main() {

    vector<int> machines{1, 0, 5};
    Solution solution;
    cout << solution.findMinMoves(machines) << endl;
    return 0;
}